package cn.tedu.myioc;

import java.util.*;

public class MyIOC{
    private List<Bean>beanfactory=new ArrayList<>();
    public MyIOC() throws Exception {
        Bean b1=new Bean("user","cn.tedu.myioc.User");
        Bean b2=new Bean("dept","cn.tedu.myioc.Dept");
        Collections.addAll(beanfactory,b1,b2);
        createObj();
    }
    Map<String,Object> map = new HashMap<>();
    public void createObj() throws Exception {
        for(Bean b :beanfactory){
            String k = b.getName();
            Object v = Class.forName(b.getPath()).newInstance();
            map.put(k,v);
        }
    }
    public Object getBean(String name){
        return map.get(name);
    }

}
